package CutLoad.mc
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class mcMouseOverOut
	{
		private var target:Sprite;
		private var obj:Object
		private var spKuang:Sprite;
		/**
		 *  
		 * @param target 设置目标
		 * @param obj {t:类型,color:色,alpha:透明度,w:宽,h:高,line:线粗(类型为2才可以用)}
		 * <p>类型0,在用目标Graphics画一个方块</p>
		 * <p>类型1,在目标中新建一个Sprite,并用它的Graphics画一个方块</p>
		 * <p>类型2,在目标中新建一个Sprite,并用它的Graphics画一个框</p>
		 * 
		 */		
		public function mcMouseOverOut(target:Sprite,obj:Object=null)
		{
			this.obj=obj;
			if(obj==null){
				this.obj.t=0;
				this.obj.color=0xffffff;
				this.obj.alpha=0.3;
				this.obj.w=target.width;
				this.obj.h=target.height;
			}
			
			if(obj.t==1||obj.t==2){
				spKuang=new Sprite();
				target.addChild(spKuang);
			}
			
			if(obj.t==2){
				if(obj.line==null) obj.line=2;
			}
			
			this.target=target;
			target.addEventListener(MouseEvent.MOUSE_OVER,over);
			target.addEventListener(MouseEvent.MOUSE_OUT,out);
			//target.stage.addEventListener(MouseEvent.MOUSE_UP,up);
		}
		private function over(e:MouseEvent):void{
			var g:Graphics
			if(obj.t==0){
				g=target.graphics;
				g.clear();
				g.beginFill(this.obj.color,this.obj.alpha);
				g.drawRect(0,0,obj.w,obj.h);
				g.endFill();
			}else{
				g=spKuang.graphics;
				g.clear();
				if(obj.t==1){
					g.beginFill(this.obj.color,this.obj.alpha);
				}else if(obj.t==2){
					g.lineStyle(obj.line,this.obj.color,this.obj.alpha);
					g.beginFill(this.obj.color,0);
				}
				g.drawRect(0,0,obj.w,obj.h);
				g.endFill();
			}
		}
		private function out(e:MouseEvent):void{
			var g:Graphics
			if(obj.t==0){
				g=target.graphics;
				g.clear();
			}else{
				g=spKuang.graphics;
				g.clear();
			}
		}
		private function up(e:MouseEvent):void{
			
		}
	}
}